define([] , function(){
	var controller = function( $scope , $timeout , $ajax , $element ){
		console.log( '自动输入框：' , $scope.fields ) ;
		var handler = {
			init 	: 	function(){
				this.initValidation() ;
				return this ;
			},
			initValidation 	: 	function(){
				var form = $($element).parents('form') ;
				if( !form || !form.length || !$scope.fields || !$scope.fields.length )
					return ;

				$scope.fields.forEach( function( v , k ){
					v.forEach( function( sv , sk ){
						var field = $($element).find('[name='+sv['name']+']') ;
						if( !field || !field.length || !field.rules )
							return ;
						field.rules('add' , sv['rule'] ) ;
						console.log( '初始化校验' , field.attr('name') , sv['rule'])
					});
				});
			}
		} ;

		$timeout( function(){
			handler.init() ;
		});
	}
	app.register.directive('ngDataInput' , function(){
		return {
			restrict 	: 	'E' ,
			replace 	: 	true ,
			scope 		: 	{
				fields 	: 	'=fields' ,
				data 	: 	'=data'
			},
			templateUrl : 	'assets/modules/ng-data-input/template.html' ,
			controller 	: 	controller 
		}
	});
});